#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
int U[MAXN], D[MAXN];
int n, X;

bool chk(long long H) {
    // L[i]: max(H-D[i], 0)
    // R[i]: U[i]
    long long lstL = max(H - D[1], 0ll), lstR = U[1];
    for (int i = 2; i <= n; ++i) {
        // max(H-D[i], 0) <= X[i] <= U[i]
        // lstL-X <= X[i] <= lstR+X

        lstL = max({lstL - X, H - D[i], 0ll});
        lstR = min(U[i], lstR + X);
        if (lstL > lstR)
            return false;
    }
    return true;
}

int main() {
    scanf("%d%d", &n, &X);
    long long l = 0, r = 2e9, ans = -1, sm = 0;
    for (int i = 1; i <= n; ++i) {
        scanf("%d%d", U + i, D + i);
        r = min(r, 1ll * U[i] + D[i]);
        sm += U[i] + D[i];
    }

    while (l <= r) {
        long long mid = (l + r) >> 1;
        if (chk(mid))
            ans = mid, l = mid + 1;
        else
            r = mid - 1;
    }

    printf("%lld\n", sm - n * ans);

    return 0;
}